package com.xiaoshu.thread;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;

/**
 * 
 * 
 * 功能说明：
 * 
 * ThreadPoolsConfiguration
 * 
 * Original Author: deane.jia,2017年7月18日下午9:53:18
 * 
 * Copyright (C)2014-2017 小树盛凯科技  All rights reserved.
 */
@Component
@Configuration
@ConditionalOnBean(ThreadPoolsProperties.class)
@EnableConfigurationProperties
@AutoConfigureAfter(ThreadPoolsProperties.class)
public class ThreadPoolsConfiguration {

	private final static Logger logger = LoggerFactory.getLogger(ThreadPoolsConfiguration.class);
	@Autowired
	private ThreadPoolsProperties threadPoolsProperties;

	@Bean
	public ThreadPoolTaskExecutor getThreadPoolExecutor() {
		logger.info("====>  start constructure the Thread Pools Executors <====");

		ThreadPoolTaskExecutor executors = new ThreadPoolTaskExecutor();
		executors.setCorePoolSize(threadPoolsProperties.getCorePoolSize());
		executors.setMaxPoolSize(threadPoolsProperties.getMaxPoolSize());
		executors.setQueueCapacity(threadPoolsProperties.getQueueCapacity());
		executors.setKeepAliveSeconds(threadPoolsProperties.getKeepAliveSeconds());
		return executors;
		
	}

}
